/**
 * Created by dell4 on 2016/5/18.
 */

function getUrl(){
    //遍历顶部导航栏
    for(var i=0; i<=getJsonnav.navName.length-1;i++)
    {
        try {
            var setHtml="<li>"+getJsonnav.navName[i].topNav+"</li>"
            $(".setTopnav").append(setHtml)
        } catch(e){

        }

    }

    //初始化遍历侧边导航
    setLeftnav(getJsonnav.navName[0].topNav)

    $(document).on("click",".setTopnav li",function(){
        $(this).parent().find("li").removeClass("class_add");
        $(this).addClass("class_add");
        $(".ziji_ul").html("")
        var thisValue=$(this).html();
        setLeftnav(thisValue)
    })

    //ajax页面载入
    var loadingDom='<div class="ds_loading_box"><i class="fa fa-spinner fa-pulse"></i>页面载入中...</div>';
    $(".user_cention_right").html(loadingDom);
    $.ajax(
        {
            type: "get",
            url: getJsonnav.indexPage,
            success:function(data)
            {
                $(".user_cention_right").html(data);

                var JPlaceHolder = {
                    //检测
                    _check : function(){
                        return 'placeholder' in document.createElement('input');
                    },
                    //初始化
                    init : function(){
                        if(!this._check()){
                            this.fix();
                        }
                    },
                    //修复
                    fix : function(){
                        jQuery(':input[placeholder]').each(function(index, element) {
                            var self = $(this), txt = self.attr('placeholder');
                            self.wrap($('<div></div>').css({position:'relative', zoom:'1', border:'none', background:'none', padding:'none', margin:'none'}));
                            var pos = self.position(), h = self.outerHeight(true), paddingleft = self.css('padding-left');
                            var holder = $('<span></span>').text(txt).css({position:'absolute', left:pos.left, top:pos.top, height:h, lienHeight:h, paddingLeft:paddingleft, color:'#aaa'}).css("line-height",""+h+"px").css("font-size","14px").appendTo(self.parent());
                            if(self.val()!=""){
                                holder.hide();
                            }
                            self.focusin(function(e) {
                                holder.hide();
                            }).focusout(function(e) {
                                if(!self.val()){
                                    holder.show();
                                }

                            });
                            holder.click(function(e) {
                                holder.hide();
                                self.focus();
                            });
                        });
                    }
                };
                //执行
                jQuery(function(){
                    JPlaceHolder.init();
                });
                setDocument();
            },
            error:function()
            {
                alert("网络断开连接！")
            }

        })

    //ajax点击不同按钮载入不同页面内容

    $(document).on("click",".user_ziji",function(){
        $(this).parent().find(".user_ziji").removeClass("user_zijiclass")
        $(this).addClass("user_zijiclass")
        var urlDo=$(this).html();
        urlDo=getButtonurl(urlDo)
        var loadingDom='<div class="ds_loading_box"><i class="fa fa-spinner fa-pulse"></i>页面载入中...</div>';
        $(".user_cention_right").html(loadingDom);
        $.ajax(
            {
                type: "get",
                url: urlDo,
                success:function(data)
                {
                    $(".user_cention_right").html(data);

                    var JPlaceHolder = {
                        //检测
                        _check : function(){
                            return 'placeholder' in document.createElement('input');
                        },
                        //初始化
                        init : function(){
                            if(!this._check()){
                                this.fix();
                            }
                        },
                        //修复
                        fix : function(){
                            jQuery(':input[placeholder]').each(function(index, element) {
                                var self = $(this), txt = self.attr('placeholder');
                                self.wrap($('<div></div>').css({position:'relative', zoom:'1', border:'none', background:'none', padding:'none', margin:'none'}));
                                var pos = self.position(), h = self.outerHeight(true), paddingleft = self.css('padding-left');
                                var holder = $('<span></span>').text(txt).css({position:'absolute', left:pos.left, top:pos.top, height:h, lienHeight:h, paddingLeft:paddingleft, color:'#aaa'}).css("line-height",""+h+"px").css("font-size","14px").appendTo(self.parent());
                                if(self.val()!=""){
                                    holder.hide();
                                }
                                self.focusin(function(e) {
                                    holder.hide();
                                }).focusout(function(e) {
                                    if(!self.val()){
                                        holder.show();
                                    }

                                });
                                holder.click(function(e) {
                                    holder.hide();
                                    self.focus();
                                });
                            });
                        }
                    };
                    //执行
                    jQuery(function(){
                        JPlaceHolder.init();
                    });
                    setDocument()
                },
                error:function()
                {
                    alert("网络断开连接！")
                }

            })
    })

    //设置left页面的全局高度铺满全屏
    setDocument()
    window.onresize=function(){
        setDocument()
    }

    $(".user_fuji").click(function(){
        if( $(this).hasClass("jt_right"))
        {
            $(this).removeClass("jt_right");
            $(this).addClass("jt_down");
        }else
        {
            $(this).addClass("jt_right");
            $(this).removeClass("jt_down");
        }
        if( $(this).next().hasClass("ziji_ul"))
        {
            $(this).next().fadeToggle(100);
        }
    })

    $(".shouqi").click(function(){
        if($(this).hasClass("zk"))
        {
            $(this).removeClass("zk");
            $(".user_cention_left").fadeIn(0);
            $(this).css("left","200px");
            $(this).html("<<")
            $(this).attr("title","点击收起");
            var wWidth=$(window).width();
            var wWidththis=wWidth-194;
            $(".user_cention_right").css("width",""+wWidththis+"px");

        }else
        {
            $(this).addClass("zk");
            $(".user_cention_left").fadeOut(0);
            $(this).css("left","0px");
            $(this).html(">>")
            $(this).attr("title","点击展开");
            var wWidth=$(window).width();
            var wWidththis=wWidth-10;
            $(".user_cention_right").css("width",""+wWidththis+"px");
        }
    })




}




//回调遍历屏幕自适应
function setDocument()
{
    setHeightleft("user_cention_left");
    setHeightleft("user_cention_right");
    setWidthleft("user_cention_right");
    setHeightleft2("widget-body",240)
}


//遍历侧边导航栏
function setLeftnav(getTopnav){

    for(var i=0; i<=getJsonnav.navName.length-1;i++)
    {
        try {
            if(getJsonnav.navName[i].topNav==getTopnav)
            {
                for(var j=0; j<=getJsonnav.navName[i].leftNav.length-1;j++)
                {

                    var setHtml="<li class='user_ziji' style='background: url("+getJsonnav.navName[i].leftNav[j][2]+") no-repeat  16px -36px '>"+getJsonnav.navName[i].leftNav[j][0]+"</li>"
                    $(".ziji_ul").append(setHtml)

                }
            }
        } catch (e){

        }
    }
}

//获取每个侧边按钮的URL
function getButtonurl(getButton){

    for(var i=0; i<=getJsonnav.navName.length-1;i++)
    {
        for(var j=0; j<=getJsonnav.navName[i].leftNav.length-1;j++)
        {
            try {
                if(getJsonnav.navName[i].leftNav[j][0]==getButton){

                    return getJsonnav.navName[i].leftNav[j][1];

                }
            }catch (e){}
        }
    }
}

//设置left页面的全局高度铺满全屏
function setHeightleft(className){
    var wHeight=$(window).height();
    var wHeightthis=wHeight-50;
    $("."+className+"").css("height",""+wHeightthis+"px");
}
function setHeightleft2(className,setHeight){
    var wHeight=$(window).height();
    var wHeightthis=wHeight-setHeight;
    $("."+className+"").css("height",""+wHeightthis+"px");
}
function setWidthleft(className){
    var wWidth=$(window).width();
    var wWidththis=wWidth-194;
    $("."+className+"").css("width",""+wWidththis+"px");
}

function hrefUrl(urlView)
{
    //ajax页面载入
    var loadingDom='<div class="ds_loading_box"><i class="fa fa-spinner fa-pulse"></i>页面载入中...</div>';
    $(".user_cention_right").html(loadingDom);
    $.ajax(
        {
            type: "get",
            url: urlView,
            success:function(data)
            {
                $(".user_cention_right").html(data);

                var JPlaceHolder = {
                    //检测
                    _check : function(){
                        return 'placeholder' in document.createElement('input');
                    },
                    //初始化
                    init : function(){
                        if(!this._check()){
                            this.fix();
                        }
                    },
                    //修复
                    fix : function(){
                        jQuery(':input[placeholder]').each(function(index, element) {
                            var self = $(this), txt = self.attr('placeholder');
                            self.wrap($('<div></div>').css({position:'relative', zoom:'1', border:'none', background:'none', padding:'none', margin:'none'}));
                            var pos = self.position(), h = self.outerHeight(true), paddingleft = self.css('padding-left');
                            var holder = $('<span></span>').text(txt).css({position:'absolute', left:pos.left, top:pos.top, height:h, lienHeight:h, paddingLeft:paddingleft, color:'#aaa'}).css("line-height",""+h+"px").css("font-size","14px").appendTo(self.parent());
                            if(self.val()!=""){
                                holder.hide();
                            }
                            self.focusin(function(e) {
                                holder.hide();
                            }).focusout(function(e) {
                                if(!self.val()){
                                    holder.show();
                                }

                            });
                            holder.click(function(e) {
                                holder.hide();
                                self.focus();
                            });
                        });
                    }
                };
                //执行
                jQuery(function(){
                    JPlaceHolder.init();
                });
                setDocument()
            },
            error:function()
            {
                alert("网络断开连接！")
            }

        })
}